package com.example.download;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.ActionBarActivity;
import android.widget.ProgressBar;

public class MainActivity extends ActionBarActivity {

    private ProgressBar bar;
    private static Handler handler;

    public static final int UPDATE = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        bar = (ProgressBar) findViewById(R.id.progressBar);
        bar.setMax(100);
        handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                switch (msg.what) {
                    case UPDATE:
                        bar.setProgress(Integer.parseInt(msg.obj.toString()));
                        break;
                }
            }
        };
        Thread a =
                new Thread() {
                    @Override
                    public void run() {
                        super.run();
                        try {
                            Main.f();

                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                };
        a.start();

    }

    public static void sendMsg(int what, Object obj) {
        Message msg = new Message();
        msg.what = what;
        msg.obj = obj;
        handler.sendMessage(msg);
    }


}
